package com.lee.strategy.controller;

import com.lee.strategy.service.StrategyService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zfl_a
 * @date 2020/8/10
 * @project springboot_design_pattern
 */
@RestController
@RequestMapping("/strategy")
public class StrategyController {

    @Autowired
    private StrategyService strategyService ;

    /**
     * 审核流程 返回值不建议Map，可定义成响应结果对象封装
     * @param name 审核人
     * @param msg 留言内容
     * @param type 类型 2微创新 3KPI/OKR 4工作汇报，在实际工作当中根据实际业务
     * @return
     */
    @PostMapping("/audit")
    public Map<String,Object> audit(String name,String msg ,String type) {

        Map<String,Object> results = new HashMap<>();
        results.put("code","200");
        results.put("msg","审核成功");

        if(StringUtils.isBlank(type)) {
            results.put("code","-1");
            results.put("msg","请传递审核类型");
            return results ;
        }

        boolean audit = strategyService.audit(name, msg, type);
        if(!audit) {
            results.put("code","-2");
            results.put("msg","审核失败");
        }
        return results ;
    }
}
